package com.yi.internalcommon.dto;

import com.yi.internalcommon.constant.CommonStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class ResponseResult<T> {

    private int code;
    private String message;
    private T data;

    /**
     * 成功响应的方法
     * @return
     * @param <T>
     */
    public  static <T> ResponseResult success(){

        return  new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode())
                .setMessage(CommonStatusEnum.SUCCESS.getValue());
    }
    /**
     * 成功响应
     * @param data
     * @return
     * @param <T>
     */
    public static <T> ResponseResult success(T data){
        ResponseResult rr=new ResponseResult();
        rr.setCode(CommonStatusEnum.SUCCESS.getCode())
                .setData(data)
                .setMessage(CommonStatusEnum.SUCCESS.getValue());
        return  rr;
    }
    /**
     * 统一的失败
     * @param data
     * @return
     * @param <T>
     */
    public static <T> ResponseResult fail(T data){
        ResponseResult rr=new ResponseResult();
        rr.setData(data);
        return  rr;
    }
    /**
     * 失败响应
     * @param code
     * @param message
     * @return
     * @param <T>
     */

    public  static <T> ResponseResult fail(int code,String message){
        ResponseResult rr=new ResponseResult();
        rr.setCode(code).setMessage(message);
        return  rr;
    }
    /**
     * 失败响应 具体错误
     * @param code
     * @param message
     * @return
     * @param <T>
     */
    public  static <T> ResponseResult fail(int code,String message,String data){
        ResponseResult rr=new ResponseResult();
        rr.setCode(code).setMessage(message).setData(data);
        return  rr;
    }

}
